home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / SBDAC.ARJ / DACDIR.C next >
C/C++ Source or Header  |  1992-02-09  |  1KB  |  79 lines

  1. /* Output to SB DAC in single sample mode */
  2.  
  3. #include <stdio.h>
  4. #include <dos.h>
  5. #include <conio.h>
  6. #include <io.h>
  7. #include <alloc.h>
  8. #include <dos.h>
  9.  
  10. int InitSB(void);
  11. extern unsigned IOaddr;
  12. extern unsigned IRQ;
  13.  
  14. /* Set voice on or off */
  15. void SetVoice(int state)
  16. {
  17.     while(inportb(0x22c) & 0x80)
  18.         ;
  19.     outportb(0x22c,(state) ? 0xd1 : 0xd3);
  20. }
  21.  
  22. /* Read first 64000 bytes of a raw sample file and play the sample */
  23. void main(int argc, char *argv[])
  24. {
  25.     FILE *f;
  26.     signed char *raw;
  27.     unsigned sample_len;
  28.     register int j, i;
  29.     int tmp;
  30.  
  31.     if(argc != 2)
  32.     {
  33.     puts("Usage: dacdir sample_file");
  34.     exit(1);
  35.     }
  36.  
  37.     if(InitSB())
  38.     {
  39.     printf("Could not find Soundblaster!\n");
  40.     exit(1);
  41.     }
  42.     printf("Found Soundblaster at %xh.\n",IOaddr);
  43.  
  44.     f = fopen(argv[1],"rb");
  45.     if(f == NULL)
  46.     {
  47.     printf("Could not open sample file %s\n",argv[1]);
  48.     }
  49.     sample_len = (unsigned)filelength(fileno(f));
  50.  
  51.     raw = (signed char *)malloc(sample_len);
  52.     fread(raw,1,sample_len,f);
  53.  
  54.     fclose(f);
  55.  
  56.     SetVoice(1);
  57.  
  58.     for(i = 0; i < sample_len; i++)
  59.     {
  60.     while(inportb(0x22c) & 0x80)
  61.         ;
  62.     outportb(0x22c,0x10);
  63.     while(inportb(0x22c) & 0x80)
  64.             ;
  65.     outportb(0x22c,raw[i]);
  66.  
  67.     while(inportb(0x22e) & 0x80)
  68.         ;
  69.     }
  70.  
  71.     SetVoice(0);
  72.  
  73.     free(raw);
  74.  
  75.     InitSB();
  76.  
  77.     exit(0);
  78. }
  79.